(function (o) {
	$p = null;	//Biến Processing
})(window);

var app = {
	screen_x : 150,
	screen_y : 150
};
	 
var X = 0;
var Y = 0;
var o_w = 10;
var step = 10;
var rect = null;

/*
 * Start
 */
app.start = function(canvas_id)
{
	new Processing(canvas_id, app.init);
}

/*
 * Khởi tạo ban đầu
 */
app.init = function(p)
{
	$p = p;

	app.setup();
	$p.draw = app.draw;
	app.direction = $p.RIGHT;

	app.registEvents();
}

/*
 * Thiết lập Canvas
 */
app.setup = function()
{
	$p.size( app.screen_x, app.screen_y);
  	$p.strokeWeight( 1 );
  	$p.frameRate( 2 );  	
  	$p.background( 100 );
  	$p.stroke(0,200,100);	
  	
  	//$p.rect(X, Y, o_w, o_w);
  	
  	var rect = new Rect({x:0, y:0, width:10});
  	rect.draw();
}

/*
 * Draw canvas
 */
app.draw = function()
{	
	/*
	switch(app.direction)
	{
		case $p.UP:
			if(Y != 0)
				Y -= step;
			break;
		case $p.DOWN:
			if(Y != app.screen_y - o_w - step)
				Y += step;			
			break;
		case $p.LEFT:
			if(X != 0)
				X -= step;	
			break;
		case $p.RIGHT:
			if(X != app.screen_x - o_w - step)
				X += step;			
			break;
	}	
	
	$p.background( 100 );
	$p.rect(X, Y, o_w, o_w);
	*/
}

/*
 * Đăng ký các event
 */
app.registEvents = function()
{
	$p.keyPressed = function()	// Event nhấn keyboard
	{
		app.direction = $p.keyCode; 		
	}
}